class Solution:
    def rootArray(self,root,list):
        if root.left==None and root.right ==None:
            list.append(root.val)
        if root.left!=None:
            self.rootArray(root.left,list)
        if root.right != None:
            self.rootArray(root.right,list)
        

    
    def leafSimilar(self, root1, root2):
        """
        :type root1: TreeNode
        :type root2: TreeNode
        :rtype: bool
        """
        list1 = []
        list2 = []
        self.rootArray(root1,list1)
        self.rootArray(root2,list2)
        print(list1)
        print(list2)
        return list1==list2
        
        
def main():
    sol = Solution()
    print(sol.leafSimilar())
    
if __name__=="__main__":
    main()